home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
edit
/
jwpsrc.zip
/
LOOKUP.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-31
|
57KB
|
1,724 lines
/* Copyright (C) Stephen Chung, 1991-1993. All rights reserved. */
#include "jwp.h"
#ifdef CTL3D
#include <ctl3d.h>
#endif CTL3D
#define KANJIBOXBORDER AVGWIDTH
#define KANJILISTBORDER BORDERSPACE
#define SCROLLBLOCKS 5
#define OKURIGANA 0x20
#define NRSORT 2
#define MAXLIST 50
#define STROKES 0
#define BUSHU 1
typedef struct {
unsigned char strokes;
unsigned char bushu;
unsigned short int nelson;
unsigned char grade;
unsigned char on:4;
unsigned char kun:4;
unsigned char unknown:4;
unsigned char meanings:4;
unsigned char padding; // To pad it to 32 bits
unsigned long int offset;
} INFORECORD;
typedef struct {
unsigned char sortkeys[NRSORT];
KANJI jis;
} IDXRECORD;
static OFSTRUCT kinfoidxof;
static BOOL KinfoIdx = FALSE;
static int KinfoMax = -1;
static int SortKey;
static int IdxBase, NrIndex;
static int CurrentKeys[NRSORT];
static int MaxKeys[NRSORT];
static int fd;
static IDXRECORD KanjiList[MAXLIST];
static int start, stop;
static int NrInList, NrSelected;
static int EdgeGap;
static KANJI InfoChar;
#define NRJISROWS 6
static int PageNum;
static int SelRow, SelCol;
static int RowDiv, ColDiv;
static int RowPos, ColPos;
BOOL FAR PASCAL KanjiInfoProc (HWND, WORD, WORD, LONG);
static KANJI BushuSymbols[] = {
0x306c, 0x2143, 0x5026, 0x254e, 0x3235, /* 01 - 05 */
0x502d, 0x4673, 0x5035, 0x3f4d, 0x5139, /* 06 - 10 */
0x467e, 0x482c, 0x5144, 0x514c, 0x5152, /* 11 - 15 */
0x515c, 0x5161, 0x4561, 0x4e4f, 0x5231, /* 16 - 20 */
0x5238, 0x5239, 0x523e, 0x3d3d, 0x4b4e, /* 21 - 25 */
0x5247, 0x524c, 0x5253, 0x4b74, 0x387d, /* 26 - 30 */
0x5378, 0x455a, 0x3b4e, 0x5469, 0x546a, /* 31 - 35 */
0x4d3c, 0x4267, 0x3d77, 0x3b52, 0x555f, /* 36 - 40 */
0x4023, 0x3e2e, 0x5577, 0x5579, 0x4366, /* 41 - 45 [ 45 qustionable ] */
0x3b33, 0x406e, 0x3929, 0x384a, 0x3652, /* 46 - 50 */
0x3433, 0x5676, 0x5678, 0x572e, 0x5730, /* 51 - 55 */
0x5735, 0x355d, 0x4730, 0x5744, 0x5746, /* 56 - 60 [ 58 questionable ] */
0x3f34, 0x5879, 0x384d, 0x3c6a, 0x3b59, /* 61 - 65 */
0x5a3d, 0x4a38, 0x454d, 0x3654, 0x4a7d, /* 66 - 70 */
0x5a5b, 0x467c, 0x5b29, 0x376e, 0x4c5a, /* 71 - 75 */
0x3767, 0x3b5f, 0x5d46, 0x5d55, 0x5d59, /* 76 - 80 */
0x4866, 0x4c53, 0x3b61, 0x5d63, 0x3f65, /* 81 - 85 */
0x3250, 0x445e, 0x4963, 0x602b, 0x602d, /* 86 - 90 */
0x4a52, 0x3267, 0x356d, 0x3824, 0x383c, /* 91 - 95 */
0x364c, 0x313b, 0x3424, 0x3445, 0x4038, /* 96 - 100 */
0x4d51, 0x4544, 0x4925, 0x614b, 0x6222, /* 101 - 105 [ 104 questionable ] */
0x4772, 0x4869, 0x3b2e, 0x4c5c, 0x4c37, /* 106 - 110 */
0x4c70, 0x4050, 0x3c28, 0x633b, 0x3253, /* 111 - 115 [ 114 questionable ] */
0x376a, 0x4e29, 0x435d, 0x4a46, 0x3b65, /* 116 - 120 */
0x344c, 0x6626, 0x4d53, 0x3129, 0x4f37, /* 121 - 125 */
0x3c29, 0x6650, 0x3c2a, 0x6666, 0x4679, /* 126 - 130 */
0x3f43, 0x3c2b, 0x3b6a, 0x3131, 0x4065, /* 131 - 135 */
0x4124, 0x3d2e, 0x3a31, 0x3f27, 0x6767, /* 136 - 140 */
0x6948, 0x436e, 0x376c, 0x3954, 0x3061, /* 141 - 145 */
0x403e, 0x382b, 0x3351, 0x3840, 0x432b, /* 146 - 150 */
0x4626, 0x6c35, 0x6c38, 0x332d, 0x4056, /* 151 - 155 */
0x4176, 0x422d, 0x3f48, 0x3c56, 0x3f49, /* 156 - 160 */
0x4324, 0x6d68, 0x4d38, 0x4653, 0x4850, /* 161 - 165 [ 162 questionable ] */
0x4e24, 0x3662, 0x4439, 0x4c67, 0x496c, /* 166 - 170 */
0x7030, 0x7032, 0x312b, 0x4044, 0x4873, /* 171 - 175 */
0x4c4c, 0x3357, 0x706a, 0x706c, 0x323b, /* 176 - 180 */
0x4a47, 0x4977, 0x4874, 0x3f29, 0x3c73, /* 181 - 185 */
0x3961, 0x474f, 0x397c, 0x3962, 0x7175, /* 186 - 190 */
0x7228, 0x722e, 0x722f, 0x3534, 0x357b, /* 191 - 195 */
0x443b, 0x7343, 0x3c2f, 0x734e, 0x4b63, /* 196 - 200 */
0x322b, 0x3550, 0x3975, 0x7363, 0x7366, /* 201 - 205 */
0x4524, 0x385d, 0x414d, 0x4921, 0x736e, /* 206 - 210 */
0x736f, 0x4e36, 0x737d, 0x737e, 0x2121, /* 211 - 215 */
0x2121, 0x2121, 0x2121, 0x2121, 0x2121, /* 216 - 220 */
0x2121, 0x2121, 0x2121, 0x2121, 0x2121, /* 221 - 225 */
0x2121, 0x2121, 0x2121, 0x2121, 0x2121, /* 226 - 230 */
0x2121, 0x2121, 0x2121, 0x2121, 0x2121, /* 231 - 235 */
0x2121, 0x2121, 0x2121, 0x2121, 0x2121, /* 236 - 240 */
0x2121, 0x2121, 0x2121, 0x2121, 0x2121, /* 241 - 245 */
0x2121, 0x2121, 0x2121, 0x2121, 0x2121, /* 246 - 250 */
0x2121, 0x2121, 0x2121, 0x2121, 0x2121 /* 251 - 255 */
};
void SetKanjiInfoChar (KANJI ch)
{
InfoChar = ch;
}
static int KeysComp (int keys[], IDXRECORD record, int SortKey)
{
int i;
if (keys[SortKey] != record.sortkeys[SortKey])
return (keys[SortKey] - record.sortkeys[SortKey]);
for (i = 0; i < NRSORT; i++) {
if (i == SortKey) continue;
if (keys[i] != record.sortkeys[i])
return (keys[i] - record.sortkeys[i]);
}
return (0);
}
static int BinarySearchIndex (int fd, int which, BOOL lower)
{
int top, bottom, middle;
int diff;
IDXRECORD record;
/* Now binary search */
top = 0;
bottom = NrIndex - 1;
for (;;) {
middle = (top + bottom) / 2;
lseek(fd, IdxBase * which + middle * sizeof(IDXRECORD), 0L);
read(fd, &record, sizeof(IDXRECORD));
diff = KeysComp(CurrentKeys, record, which);
if (diff == 0) {
/* Move to the beginning */
while (middle >= 0) {
lseek(fd, IdxBase * which + middle * sizeof(IDXRECORD), 0);
read(fd, &record, sizeof(IDXRECORD));
if (KeysComp(CurrentKeys, record, which) > 0) break;
middle--;
}
return (middle + 1);
}
if (top >= bottom - 1) return (lower ? bottom : top);
if (diff > 0) top = middle;
else bottom = middle;
}
}
static void PerformSearch (HWND hwnd, int fd, BOOL direction, BOOL MainKey)
{
int i, j;
IDXRECORD record;
HCURSOR hCursor;
hCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
ShowCursor(TRUE);
/* Now binary search the list */
j = BinarySearchIndex(fd, SortKey, TRUE);
lseek(fd, IdxBase * SortKey + j * sizeof(IDXRECORD), 0);
read(fd, &record, sizeof(IDXRECORD));
if (MainKey) {
if (!direction) {
if (CurrentKeys[SortKey] != record.sortkeys[SortKey]) j--;
}
} else {
if (direction) {
if (CurrentKeys[SortKey] != record.sortkeys[SortKey]) j--;
} else {
if (KeysComp(CurrentKeys, record, SortKey) < 0) {
lseek(fd, IdxBase * SortKey + (j-1) * sizeof(IDXRECORD), 0);
read(fd, &record, sizeof(IDXRECORD));
if (CurrentKeys[SortKey] == record.sortkeys[SortKey]) j--;
}
}
}
start = j - NrSelected;
stop = start + NrInList - 1;
lseek(fd, SortKey * IdxBase, 0);
if (start > 0) lseek(fd, start * sizeof(IDXRECORD), 1);
for (j = 0; j < NrInList; j++) {
if (start + j < 0 || start + j >= NrIndex) {
KanjiList[j].jis = 0;
} else {
read(fd, &record, sizeof(IDXRECORD));
KanjiList[j] = record;
}
if (j != NrSelected) continue;
for (i = 0; i < NRSORT; i++) {
if (record.sortkeys[i] != CurrentKeys[i]) {
CurrentKeys[i] = record.sortkeys[i];
SetScrollPos(GetDlgItem(hwnd, 4221 + i), SB_CTL, CurrentKeys[i], TRUE);
SetDlgItemInt(hwnd, 4231 + i, CurrentKeys[i], TRUE);
}
}
}
InvalidateRect(GetDlgItem(hwnd, 4201), NULL, FALSE);
SendDlgItemMessage(hwnd, 4201, WM_USER, 0, 0L);
ShowCursor(FALSE);
SetCursor(hCursor);
}
BOOL FAR PASCAL LookupProc (HWND hwnd, WORD message, WORD wParam,